<?php
session_start(); 
$teacher_id=$_SESSION['id'];
$_SESSION['set_change'] = $_GET[set_id];
require_once('../include/connect.inc.php');
require_once('../include/layout-jquery.php');
	if($_SESSION['sess_id'] <> session_id()){
	?>
 	<SCRIPT LANGUAGE="JavaScript">
		alert("กรุณาเข้าสู่ระบบให้ถูกต้องตามขั้นตอน...!");
		location="login.php";
	</script>
<?php }?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Model Test Program</title>
<link rel="stylesheet" type="text/css" href="../template/template_style_wood.css">
</head>

<body>
<div id="menu"><div><img src="../images/icon-m.png" /></div>
<div id="menulinks">
		<a  href="../person_tea.php">ข้อมูลส่วนตัว</a>
		<a href="../tea_edit.php">เปลี่ยนรหัสผ่านใหม่</a>
        
        <a href="show_subject.php">จัดการรายวิชา</a>
		<a  href="../teacher_test.php">จัดการข้อสอบ</a>
        <a class="active" href="../teacher_tests.php">จัดการชุดข้อสอบ</a>
        <a  href="../agree_set.php">กำหนดสิทธิ์</a>
		<a href="../exam/tea_chack.php">ตรวจสอบคะแนน</a>
        <a href="../news/manage_news.php">ประกาศข่าวสาร</a>
        <a href="../problem/send_problem.php">แสดงความคิดเห็น</a>
        <a href="../logout.php">ออกจากระบบ</a>
		</div></div>       
<div id="p3">    
<div id="header"></div>
<div id="page"><div id="p1">คุณ<?php echo $_SESSION['teacher_name'];?><hr/>    
<form id="form1" name="form1" method="post" action="">
 <table  border="0" cellspacing="0" cellpadding="0">
     <tr>
        <th align="left"><font size="+1">ข้อสอบชุดที่ <?php echo $_SESSION['set_change'];?></font></th>
        <th align="right"><a href="frm_manage_set.php"><img src="../images/undo.png" border="0" /></a></th>
    </tr>
</table>
<input type="hidden" name="set_id" id="set_id" value="<?php echo $_SESSION['set_change']?>">
<?php
//เลือกแสดงชุดข้อสอบ จากค่าID ชุดที่เลือกมา
$number=0;
$count=0;
$query = query("SELECT * FROM tb_set_detail where set_id='".$_SESSION['set_change']."' order by match_set_cho DESC");
	while ($rs = fetch_array($query)) {
		$match_set_cho=$rs['match_set_cho'];
		$question_id=$rs['question_id'];
?>

<?php if ($rs['match_set_cho']!=""){?>
<div class="p21">
 <a href="frm_manage_change.php?choose_id=<?php echo $match_set_cho;?>&type_id=5" onClick="return confirm('ยืนยันการเปลี่ยนชุดข้อสอบ *จับคู่* ชุดนี้')"><img src="../images/change.jpg" border="0" /></a>
 ข้อสอบประเภท จับคู่!
<table border="0"  id="table-t" width="45%">
    <tr>
      <td width="187"><strong>คำถาม</strong></td>
      <td width="198"><strong>คำตอบ</strong></td>
    </tr>
<?php 
$num=0;
	$queryQ=query("SELECT * FROM tb_question where match_set=$match_set_cho order by question_id ASC");
		while ($rsQ = fetch_array($queryQ)) {
			$ques_match_id=$rsQ['question_id'];
			$ques_match_detail=$rsQ['question_detail'];
			$type_id=$rsQ['type_id'];
			$num++;
?>
    <tr>
    	<input type="hidden" name="type[]" id="type[]" value="<?php echo "$type_id";?>">
    	<input type="hidden" name="q_id[]" id="q_id[]" value="<?php echo "$ques_match_id";?>">
		<td>ข้อที่ <?php echo "$num";?>)<?php echo "$ques_match_detail";?></td>
      	<td><select name="choice[]<?=$count?>2" id="choice[]<?=$count?>">
          <option value="0">---เลือกคำตอบ---</option>
          <?php 
	$queryC=query("SELECT * FROM tb_choice where match_set=$match_set_cho order by choice_id ASC");
		while ($rsC = fetch_array($queryC)) {
			$choice_id=$rsC['choice_id'];
			$choice_detail=$rsC['choice_detail'];
?>
          <option value="<?php echo "$choice_id";?>"><?php echo "$choice_detail";?></option>
          <?php }?>
        </select></td>
   	  </tr>
<?php }?>
</table>
<?php echo "<br/>";?>
</div>
<?php }?>

<?php
//เลือกแสดงข้อสอบ ตามID ของรายละเอียดชุด
$query2= query("SELECT * FROM  tb_question where question_id='".$question_id."' ORDER BY type_id desc");
	while ($rs2= fetch_array($query2)) {
		$question_id2=$rs2['question_id'];
		$question_detail=$rs2['question_detail'];
		$type_id=$rs2['type_id'];
		$number++;
?>
<div class="p21">
<?php 
$queryT= query("SELECT * FROM  tb_type where type_id='$type_id' ");
	while ($rsT= fetch_array($queryT)){
		$type=$rsT['type_name'];
?>
ข้อสอบประเภท"<?php echo "$type";?>"
<?php }?>
<table border="0"  id="table-t" width="40%">
	<tr>
		<td>
		<div>
		<input type="hidden" name="type[]" id="type[]" value="<?=$rs2[type_id] ?>">
		<input type="hidden" name="q_id[]" id="q_id[]" value="<?=$rs2[question_id] ?>">
<a href="frm_manage_change.php?choose_id=<?php echo $question_id2;?>&type_id=<?php echo $type_id;?>" onClick="return confirm('ยืนยันการเปลี่ยนข้อสอบ *<?php echo "$type"?>* ข้อนี้')"><img src="../images/change.jpg" border="0" /></a>ข้อที่ <? echo "$number"; echo ". ";?><? echo $question_detail; ?>
</div>
<?php
$query3 = query("SELECT * FROM tb_choice  where question_id='".$rs2['question_id']."'order by choice_id ASC");
	while ($rs3 = fetch_array($query3)){
	?>
<div class="p21">
<?php  if($rs2['type_id']==4){?>
	<input type="text" name="answord[]" id="answord[]" />
<?php }
	if($rs2['type_id'] != 5){
	if($rs2['type_id'] != 7){
	if($rs2['type_id'] == 2){
?>
	<label>
    	<input type="checkbox" name="choice[]<?=$count?>"  value="<? echo $rs3[choice_id];?>"  <? if  ($rs3['answer']==1){?> checked="checked" <? }?> disabled="disabled">
    </label>
<?php }else{ ?>
	<label>
		<input type="radio" name="choice[]<?=$count?>"  value="<? echo $rs3[choice_id];?>"  <? if  ($rs3['answer']==1){?> checked="checked" <? }?> disabled="disabled">
	</label>
<?php }?>
<?php  echo $rs3['choice_detail'];?>
	<?php }?>
		<?php }?>
	</div>
<?php }?>
	    <th width="30" align="left">
<?php  if($rs2['pic_name']!=""){?>
	<div align="center"><a href="../upload/<? echo  $rs2['pic_name'];?>" target="_blank">
	<img src="../upload/<?php echo  $rs2['pic_name'];?>" border="0" width=100 height=100 /></a>
	<div><small>คลิ๊กที่รูปเพื่อดูขนาดใหญ่</small></div>
	</div>
<? }?>
<?php  if($rs2['media_name']!=""){?>
<div align="center">
	<object id="mediaPlayer" height="23" width="187" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">
		<param name="fileName" value='<? echo "../upload/".$rs2['pic_name']; ?>' valuetype='ref' />
		<param name="AutoStart" value="0" />
		<param name="TransparentAtStart" value="true" />
		<param name="SendPlayStateChangeEvents" value="true" />
		<param name="ShowControls" value="0" />
		<param name="ShowDisplay" value="0" />
		<param name="ShowStatusBar" value="1" />
		<param name="ShowGotoBar" value="0" />
		<param name="ShowPositionControls" value="0" />
		<param name="AutoSize" value="0" />
		<param name="volume" value="0" />
		<param name="loop" value="0" />
	</object>
<div align="center">
	<img style="CURSOR: pointer" 
	onclick="mediaPlayer.play()" height="30" 
	src="../soundbox/play-48x48.png" 
	width="30" /><img style="CURSOR: pointer" 
	onclick="mediaPlayer.pause()" height="30" 
	src="../soundbox/puse-48x48.png" 
	width="30" /><img 
	src="../soundbox/stop-48x48.png" 
	width="30" height="30" style="CURSOR: pointer" 
	onclick="mediaPlayer.stop()" /></div>
</div>
<? }?>	
		</th>
	</tr>
</table>
<?php echo "<br/>";?>
</div>
<? }?>
<? $count++;?> 
<? }?>
</form>
    </div>
    </div>
<div id="footer"></div>
</div>
</body>
</html>
